package com.geqian.web.controller;

import com.geqian.common.common.PageRequest;
import com.geqian.common.common.PageResult;
import com.geqian.common.common.ResponseResult;
import com.geqian.web.entity.Table;
import com.geqian.web.service.TableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/table")
@Api(tags = "数据表")
public class TableController {

    @Resource
    private TableService tableService;

    @ApiOperation("获取数据表列表")
    @GetMapping("/getTableList")
    public ResponseResult<PageResult<Table>> getTableList(PageRequest pageRequest) {
        return tableService.getTableList(pageRequest);
    }


    @ApiOperation("更新数据表")
    @PostMapping("/updateTable")
    public ResponseResult<String> updateTable(@RequestBody Table table, @RequestHeader("token") String token) {
        return tableService.updateTable(table, token);
    }


    @ApiOperation("新增数据表")
    @PostMapping("/addTable")
    public ResponseResult<String> addTable(@RequestBody Table table, @RequestHeader("token") String token) {
        return tableService.addTable(table, token);
    }

    @ApiOperation("删除数据表")
    @PostMapping("/deleteTable")
    public ResponseResult<String> deleteTable(@RequestBody List<Table> tableList) {
        return tableService.deleteTable(tableList);
    }


    @ApiOperation("查询所有表名")
    @GetMapping("/getTableNames")
    public ResponseResult<List<String>> getTableNames() {
        return tableService.getTableNames();
    }


    @ApiOperation("导入数据表")
    @GetMapping("/importTable")
    public ResponseResult<String> importTable(@RequestParam("tableName") String tableName) {
        return tableService.importTable(tableName);
    }


    @ApiOperation("生成代码")
    @PostMapping("/generateCode")
    public ResponseResult<String> generateCode(@RequestBody Table table, @RequestHeader("token") String token) {
        return tableService.generateCode(table, token);
    }


    @ApiOperation("卸载代码")
    @PostMapping("/uninstall")
    public ResponseResult<String> uninstall(@RequestBody Table table) {
        return tableService.uninstall(table);
    }
}